<%--
Copyright (c) 2004-2006 BroadVision, Inc.  All rights reserved.

This software is copyrighted. Under the copyright laws, this software
may not be copied, in whole or in part, without prior written consent
of BroadVision, Inc. or its assignees. This software is provided
under the terms of a license between BroadVision and the recipient,
and its use is subject to the terms of that license.

This software may be protected by one or more U.S. and International
patents.  Certain applications of BroadVision One-To-One software are
covered by U.S. patent 5,710,887.

TRADEMARKS: BroadVision and BroadVision One-To-One are registered
trademarks of BroadVision, Inc., in the United States and the
European Community, and are trademarks of BroadVision, Inc., in other
countries.  The BroadVision logo, is a trademark of BroadVision,
Inc., in the United States and other countries. Additionally, IONA
and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and
RC2 are trademarks of RSA Data Security, Inc.

--%><%@ taglib uri="/WEB-INF/c.tld" prefix="c"
%><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"
%><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"
%><%@ page import="java.util.List"
%><%@ page import="org.apache.struts.util.RequestUtils"
%><%@ page import="com.broadvision.web.action.LoginAction"
%><%@ page import="com.broadvision.web.util.ValuePair"
%><%

  String ctxPath = request.getContextPath();

  /*
   *************************************************************
   *
   *                      Important Note 
   *
   ************************************************************* 
    For the form action, if we just use <html:form action="/mc/login.do">
    in IM environment, it will attach some session informatin after login.do.
    If the user comes this first page and stays here till session time-out,
    then even if the user inputs correct user name and password, the IM will
    still complains about invalid session. In order to fix this problem, we
    should not append any session informatin after "/mc/login.do". So we
    will not use <html:form> tag, but generates the action by coding.
   **************************************************************
  */
  String formActionUrl = RequestUtils.computeURL(pageContext,
                                                 null,
                                                 null,
                                                 "/mc/login.do",
                                                 null,
                                                 null,
                                                 false);
  //Since the computeURL will automatically append session information after "/mc/login.do",
  //So we need remove those session information.
  //remove bvsession and bveng information from the Url.
  int questionmarkLoc = formActionUrl.indexOf("?");
  if (questionmarkLoc > 0) formActionUrl = formActionUrl.substring (0, questionmarkLoc); 
  //remove ";jsessionid" for IM-free.
  int jsessionidLoc = formActionUrl.indexOf(";jessionid=");
  if (jsessionidLoc > 0) formActionUrl = formActionUrl.substring (0, jsessionidLoc);
%>

<script language="JavaScript" type="text/javascript">

var passwordFocus = false;

//
//
//
function setPasswordFocus(focus) {
  passwordFocus = focus;
}

//
//
//
function onLoad() {
  if (passwordFocus) {
    document.loginForm.password.focus(); 
  }
  else {
    document.loginForm.username.focus();
  }
}

//
//
//
function onLogin(theForm) {
  if (theForm.username.value == "") {
    theForm.username.focus ();
    return false;
  }
  else if (theForm.password.value == "") {
    theForm.password.focus ();
    return false;
  }

  return saveDataToCookies(theForm);
}

//
//
//
function saveDataToCookies(theForm) {
  var result = true;
  var cookieStatus = cookiesEnabled ();

  if (theForm.saveUserName.checked) {
    //The user selected the check box.
    if (cookieStatus.length == 0) {
      registerCookie ("saveUserName", 1);
      registerCookie ("username", theForm.username.value);
    }
    else {
      result = confirm (cookieStatus + '<bean:message key="mc.common.login.alert.notSaveOrEnableCookie" bundle="mc.messages"/>');
    }
  }
  else {
    //The user didn't select the check box. so we need clear the cookie.
    if (cookieStatus.length == 0) {
      if (getCookie("SaveUserName") != "") registerCookie ("saveUserName", null);
      if (getCookie("username") != "") registerCookie ("username", null);
    }
  }
  return result;
}

//
//
//
function setCookie(name, value, expire) {
  var result = name + "=";
  if (value != null) result = name + "=" + escape(value) 
                      + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
  document.cookie = result;
}

//
//
//
function getCookie(name) {
  var search = name + "=";
  if (document.cookie.length > 0) {
    // if there are any cookies
    var offset = document.cookie.indexOf(search);
    if (offset != -1) { 
      // if cookie exists
      offset += search.length;
      // set index of beginning of value
      end = document.cookie.indexOf(";", offset);
      // set index of end of cookie value
      if (end == -1)
        end = document.cookie.length;
      x = unescape(document.cookie.substring(offset, end));
      return x;
    }
  }
  else {
    return "";
  }
}

//
//
//
function registerCookie(name, value) {
  var today = new Date();
  var expires = new Date();   
  expires.setTime(today.getTime() + 1000*60*60*24*365*10); //Expire after 10 years.
  setCookie(name, value, expires);
}

//
// Check whether the user's browser is cookie enabled. If enabled, return an
// empty string. Otherwise, return a String which includes instruction about how to enable
// browser's cookie.
function cookiesEnabled() {
  var str = '<bean:message key="mc.common.login.alert.message" bundle="mc.messages"/>';
  var nsHow = '<bean:message key="mc.common.login.alert.netscapeConfigure" bundle="mc.messages"/>';
  var ieHow = '<bean:message key="mc.common.login.alert.ieConfigure" bundle="mc.messages"/>';
  var ie5How = '<bean:message key="mc.common.login.alert.ie5Configure" bundle="mc.messages"/>';
  var isIE = navigator.appName == "Microsoft Internet Explorer";
  var alertStr = "";
  if (isIE) {
    if (! navigator.cookieEnabled) {
      //MSIE 4.x AND 5.x version number is 4
      re = /MSIE (\d+\.\d+)/;
      found = navigator.userAgent.match(re);
      ieVer = found[1];
      if (ieVer >= 5) alertStr = str + ie5How;
      else alertStr = str + ieHow;
    }
  }
  else {
    document.cookie = "cookies=Ok";
    if (! document.cookie) alertStr = str + nsHow;
  }
  return alertStr;
}

</script>

<!--start zone 5 content area-->
<!--start page title area-->

<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td><img src="<%= ctxPath %>/mc/images/build/transparent.gif" width="5" height="1" alt="" border="0"></td>
    </tr>
    <tr>
        <td width="100%" id="lightNeutral"><img src="<%= ctxPath %>/mc/images/build/transparent.gif" width="5" height="1" alt="" border="0"></td>
    </tr>
    <tr>
        <td width="100%" id="darkNeutral"><img src="<%= ctxPath %>/mc/images/build/transparent.gif" width="5" height="1" alt="" border="0"></td>
    </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>

<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td width="18%">&nbsp;</td>
    <td>
      <table width="100%" border="0" cellspacing="0" cellpadding="3" align="center">
        <tr> 
          <td class="pageTitle" id="pageTitle" colspan="3"> <br>
            <span style="white-space: nowrap;"><bean:message key="mc.common.login.welcome" bundle="mc.messages"/></span><br>
          </td>
        </tr>
      </table>


    <!--end page title area-->

                

    <!--start main content area here-->
        <%-- Don't use <html:form> tag here. Reason is explained at the place where formActionUrl is defined. --%>
        <form name="loginForm" action="<%=formActionUrl%>" method="post"> 
            <%-- Don't use <html:form> tag here. Reason is explained at the place where formActionUrl is defined. --%>
            <table width="100%" border="0" cellspacing="0" cellpadding="3" align="center">
                <tr> 
                  <td colspan="3" class="errorMessage"><html:errors bundle="mc.messages"/> &nbsp; </td>
                </tr>
                <!--End page instructions here-->
                <tr class="loginInstructions"> 
                    <td nowrap width="16%" valign="middle">&nbsp;</td>
                    <td nowrap valign="top" width="84%" colspan="2"> 
                      <bean:message key="mc.common.login.warning" bundle="mc.messages"/>
                    </td>                    
                </tr>
                <tr> 
                    <td nowrap width="16%" valign="middle" class="label">
                      <bean:message key="mc.common.login.username" bundle="mc.messages"/>:</td>
                    <td nowrap valign="top" width="84%" colspan="2"> 
                      <html:text name="loginForm" property="username" size="31" maxlength="80"/>
                    </td>
                </tr>
                <tr> 
                    <td valign="middle" nowrap width="16%" class="label">
                      <bean:message key="mc.common.login.passwd" bundle="mc.messages"/>: </td>
                    <td valign="top" width="84%" colspan="2"> 
                        <input type="password" name="password" size="31" maxlength="80">
                    </td>
                </tr>

<c:if test="${!empty loginForm.serviceNameList}">
                <tr>
                    <td valign="middle" nowrap width="16%" class="label">
                      <bean:message key="mc.common.login.select" bundle="mc.messages"/>: </td>
                    <td valign="top" width="84%" colspan="2">
                      <html:select name="loginForm" property="serviceName"> 
                      <html:options name="loginForm" property="serviceNameList"/>
                      </html:select>
                    </td>
                </tr>
</c:if>

                <tr>
                    <td valign=middle nowrap width='16%' class=label>&nbsp;</td>
                    <td valign=top width='36%' nowrap class=label>
                        <input type=checkbox name='saveUserName'>
                        <bean:message key="mc.common.login.saveusername" bundle="mc.messages"/>
                    </td>
                </tr>

				<script language="javascript" type="text/javascript">
                  if (getCookie("saveUserName") == "1") {
                    document.loginForm.saveUserName.checked = true;
                  }
                  var usernameInCookie = getCookie("username");
                  if (usernameInCookie && usernameInCookie.length > 0 &&
                      document.loginForm.username.value.length == 0) {
                    document.loginForm.username.value = usernameInCookie;
                    setPasswordFocus(true);
                  }
                </script>
                <tr> 
   			      <td valign="top" nowrap width="16%" class="label">&nbsp;</td>
                  <td valign="top" class="labelField" width="84%" colspan="2">&nbsp;</td>
                </tr>
                <tr align="right"> 
                  <td nowrap width="16%" height="25">&nbsp; </td>
                  <td nowrap width="36%" height="25"> 
                     <input type="submit" 
                    value='<bean:message key="mc.common.login.button.signin" bundle="mc.messages"/>' class="inputButton" onclick="return onLogin(this.form);"> 
                  </td>
                  <td width="48%" height="25">&nbsp;</td>
                </tr>
            </table>
<c:if test="${empty loginForm.serviceNameList}">
        <html:hidden name="loginForm" property="serviceName"/>
</c:if>

<%
  List params = (List) session.getAttribute(LoginAction.NEXT_PAGE_PARAMS_KEY);
  if (null != params) {
    for (int paramIndex = 0; paramIndex < params.size(); paramIndex++) {
      ValuePair param = (ValuePair) params.get(paramIndex);
      String pName = param.getName();
      String pValue = param.getValue();
%>
        <input type=hidden name="<%= pName %>" value="<%= pValue %>">
<%
    }
  }
%>
        </form>
    </td>
    <td width="18%">&nbsp;</td>
  </tr>
</table>
<!--end main content area here-->
<!--end zone 5 content area-->
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>